#!/usr/bin/env python
import pygame
from pygame.locals import *
import sgc
from sgc.locals import *

pygame.font.init()
pygame.display.init()

screen = sgc.surface.Screen((640,480))
clock = pygame.time.Clock()

class GameOptions(object):
    """ Options For The Game"""
    def __init__(self):
        self.ExtraBaddies = False

class MenuScreen(object):
    """ Menu For The Game"""
    def __init__(self, o):
        self.Options = o
        sgc.Menu.startgame = self.startgame
        sgc.Menu.exitgame = self.exitgame
        sgc.Menu.setExtraBadGuys = self.setExtraBadGuys
        sgc.Menu.func_dict = lambda self: {"start": self.startgame, 
                               "ExtraBadGuys": self.setExtraBadGuys,
                               "exit": self.exitgame}
        self.menu = sgc.Menu(menu=open("dmenu"))
        self.MenuActive = True
        self.menu.add()
    def setExtraBadGuys(self):
        self.Options.ExtraBaddies = self.menu["extra"].state
    def startgame(self):
        self.MenuActive = False
    def exitgame(self):
        exit()
    def RunMenu(self):
        while self.MenuActive:
            time = clock.tick(30)
            for event in pygame.event.get():        
                sgc.event(event)
                if event.type == GUI:
                    pass
                elif event.type == QUIT:
                    exit()
            
            sgc.update(time)
            pygame.display.flip()

class Game(object):
    """ Pretend Game """
    def __init__(self, o):
        self.Options = o
    def Play(self, surface):
        surface.fill((255, 0, 0))
        
        while True:
            for event in pygame.event.get():        
                if event.type == QUIT:
                    exit()
                elif event.type == KEYDOWN:
                    if event.key == K_q:
                        return
            if self.Options.ExtraBaddies:
                c = Color(0,66,0)
                pygame.draw.rect(screen.image, c, Rect(80,240,33,33), 0)
                pygame.draw.rect(screen.image, c, Rect(180,240,33,33), 0)
                pygame.draw.rect(screen.image, c, Rect(280,240,33,33), 0)
            else:
                c = Color(0,0,66)
                pygame.draw.rect(screen.image, c, Rect(280,240,33,33), 0)
            pygame.display.flip()

def main():
    
    o = GameOptions()
    ms = MenuScreen(o)
    g = Game(o)
    
    while True:
        ms.MenuActive = True
        while ms.MenuActive:
            ms.RunMenu()
        g.Play(screen.image)
    
if __name__ == "__main__":
    main()
